﻿using suirui.ZhuMu.Model;
using suirui.ZhuMu.Entity;
using suirui.ZhuMu.Entity.Entities;
using System;
using System.Threading.Tasks;
using suirui.ZhuMu.Repositories;
using System.Collections.Generic;
using suirui.ZhuMu.Common.Helper;
using suirui.ZhuMu.Common;

namespace suirui.ZhuMu.Services
{
    public class RoomService : BaseServices<Room>, IRoomService
    {
        private readonly IRoomRepository _RoomRepository;

        public RoomService(IRoomRepository RoomRepository)
            : base(RoomRepository)
        {
            _RoomRepository = RoomRepository ?? throw new ArgumentNullException(nameof(RoomRepository));
        }

        public async Task<APIResult<PageData<Room>>> GetRoomList(GetParamsDto paramsDto)
        {
            PageData<Room> result = await _RoomRepository.GetRoomList(paramsDto);
            return OperateResult.QuerySuccessInfo(result);
        }

        public async Task<APIResult<Room>> GetRoomById(long Id)
        {
            Room result = await GetAsync(t => t.RoomId == Id);
            return OperateResult.QuerySuccessInfo(result);
        }

        public async Task<APIResult> AddRoom(Room health)
        {
            var result = await _RoomRepository.AddRoom(health);
            return result ? OperateResult.OperateSuccessInfo(result) : OperateResult.OperateFailInfo<Room>();
        }

        public async Task<APIResult> UpdateRoom(Room health)
        {
            var result = await _RoomRepository.UpdateRoom(health);
            return result ? OperateResult.OperateSuccessInfo(result) : OperateResult.OperateFailInfo<Room>();
        }

        public async Task<APIResult> DeleteRoom(long Id)
        {
            var health = Get(t => t.RoomId == Id);
            //health.Status = 0;//修改为逻辑删除
            var result = await UpdateAsync(health);
            return result ? OperateResult.OperateSuccessInfo(result) : OperateResult.OperateFailInfo<Room>();
        }
    }
}
